class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        maxlength=0
        queue=[]
        for c in s:
            if c not in queue:
                queue.append(c)
            else:
                if maxlength<len(queue):
                    maxlength=len(queue)
                while queue[0]!=c:
                    queue.pop(0)
                queue.pop(0)
                queue.append(c)
        if maxlength==0 or len(queue)>maxlength:
            maxlength=len(queue)
        return maxlength

s=Solution()
print(s.lengthOfLongestSubstring("pwwkew"))
